<?php

namespace Agent\Controller;

use Think\Controller;

class LoginController extends Controller {
	public function __construct() {
		parent::__construct ();
	}
	function login_check() {
		$username = I ( "username" );
		$password = I ( "password" );
		$dingge_adminModel = D ( "Agent" );
		$where ['username'] = $username;
		$where ['password'] = $password;
		if ($dingge_adminModel->where ( $where )->find ()) {
			session ( "ssc_agent", $username );
			$this->redirect ( "Agent/Index/index" );
		} else {
			$this->display ( "login" );
		}
	}
	
	// function login(){
	// $this->display();
	// }
	function login_post() {
		$Verify = new \Think\Verify ();
		if ($Verify->check ( I ( 'code' ) )) {
			$adminModel = D ( "Agent" );
			$where_find ['username'] = I ( 'username' );
			$agent_find = $adminModel->where ( $where_find )->find ();
			if ($agent_find ['status'] == 2) {
				echo "<script>alert('账号已被禁止登录，请联系客服!');location.href='" . __APP__ . "/Home/User/agent_login'</script>";
				die ();
			}
			if (decrypt ( $agent_find ['password'] ) == I ( 'password' )) {
				session ( "ssc_agent", $agent_find );
				$this->redirect ( "Agent/Index/index" );
			} else {
				$this->redirect ( "Home/User/agent_login" );
			}
		} else {
			echo "<script>alert('" . I ( 'username' ) . "验证码错误！');location.href='" . __APP__ . "/Home/User/agent_login'</script>";
			die ();
		}
	}
	function logout() {
		session ( "ssc_agent", null );
		$this->redirect ( "Home/User/agent_login" );
	}
	function google_analytics() {
		$this->display ();
	}
}